package pacificlms;

import pacificlms.MainPanel.MainPanel;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.*;
import java.awt.event.*;


import java.sql.*;
import java.util.*;
import java.text.*;


import pacificlms.Verifiable.*;
import pacificlms.Verifiable.Database.*;

import java.net.*;
import java.io.*;
import pacificlms.Error.ErrorHandle;

/**
 *
 * @author Brian Hume
 */
public class MainJApplet extends JApplet 
{

    /**
     * Initialization method that will be called after the applet is loaded into
     * the browser.
     */
    final int Width = 800, Height = 600;
    public void init() 
    {
        try {
            resize(Width, Height);
            
            if (getWidth() != Width || getHeight() != Height)
            {
                JOptionPane.showMessageDialog(this, "Warning LMS Applet set to wrong size (" + getWidth() + ", " + getHeight() + "),\nfunction may be impaired.\n\nTo fix this set the applets size to ((" + Width + ", " + Height + "))");
            }
            
            CurrentApplet = this;
            
            SwingUtilities.invokeAndWait(new Runnable() 
            {
                public void run() 
                {
                    createLoadGUI();
                }
            });
        }
        catch (Exception ex) 
        { 
            System.err.println("error creating GUI\n" + ex.toString());
        }
    }
    
    private static MainJApplet CurrentApplet;
    public static MainJApplet getApplet()
    {
        return CurrentApplet;
    }
    
    private void createLoadGUI()
    {
        LoaderPanel Loader = new LoaderPanel(getParameter("ConectionConfig"));
        Loader.setOpaque(true);
        setContentPane(Loader);
    }
    
    public void createMainGUI()
    {
        MainPanel mainView = new MainPanel();
        mainView.setOpaque(true);
        setContentPane(mainView);
        mainView.UpdateLogin();
    }
}
